import re

class PhysicalLocation(object):

  def __init__(self):
    self.BoxNumber = -1
    self.SectionNumber = -1

  def __init__(self, boxNumber, sectionNumber):
    self.BoxNumber = boxNumber
    self.SectionNumber = sectionNumber

  @staticmethod
  def FromText(text):
    m = re.search("location\(box=(\d+),section=(\d+)\)", text)
    if m is None:
      raise Exception("No location found in text.", text)
    return PhysicalLocation(int(m.group(1)), int(m.group(2)))

  def ToText(self):
    return 'location(box=%d,section=%d)' % (self.BoxNumber, self.SectionNumber)


